<script lang="ts" setup>
import { onMounted, reactive, ref } from 'vue'
import { usePopWinInject } from '../../../../common/hooks/FormHooks'
import { createRebateApi, updateRebateApi } from '../../../../common/service/api/rebateApi'


// 当前状态
const state:any = reactive({
    isLoading: false,
    formData: {
        id: null,
        name: '',
        pointOne: 0,
        pointTwo: 0
    },

    rules: {
        name: [{ required: true, message: '不能为空', trigger: 'blur' }]
    }

})

// 表单工具方法
const { formRef, actions, rootPopState } = usePopWinInject(state, {
    createMethod: createRebateApi,
    updateMethod: updateRebateApi
})

const submitHandler = () => {
    actions.submitHandler()
}

// 初始化
onMounted(() => {
    // 初始化表单
    actions.initFormData(false)
})

</script>

<template>
  <v-pop-win :title="rootPopState.isPopCreate?'添加返点配置':'编辑返点设置'"
             :width="600"
             :loading="state.isLoading"
             align-center
             @close="()=>actions.close()"
             @submit="submitHandler">
    <el-form ref="formRef"
             :style="{width:'100%'}"
             :model="state.formData"
             :rules="state.rules"
             :label-width="100"
             class="form-edit-box"
             status-icon>
      <el-form-item label="商品标题" prop="name">
        <el-input v-model.trim="state.formData.name"
                  type="textarea"
                  :rows="2"
                  :style="{width:'100%'}"
                  placeholder="请输入分销商名称"
                  maxlength="100" />
      </el-form-item>

      <el-form-item label="一级返点" prop="pointOne">
        <el-input-number v-model.trim="state.formData.pointOne"
                         :style="{width:'100%'}"
                         placeholder="请输入一级返点"
                         maxlength="100" />
      </el-form-item>

      <el-form-item label="二级返点" prop="pointTwo">
        <el-input-number v-model.trim="state.formData.pointTwo"
                         :style="{width:'100%'}"
                         placeholder="请输入二级返点"
                         maxlength="100" />
      </el-form-item>
    </el-form>
  </v-pop-win>
</template>


<style scoped lang="scss">

</style>
